﻿using BLL;
using BLL.Access;
using DevExpress.Web;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;

namespace Web.Pages.QuShui.DiXiaS._5.ShouFeiGL
{
    public partial class ZhiPiaoXJFW : BasePage
    {

        #region 属性

        /// <summary>
        /// 记录数据验证情况,为TRUE为收费可以添加
        /// </summary>
        private bool ValidateOK
        {
            get
            {
                return Convert.ToBoolean(ViewState["ValidateOK"]);
            }
            set
            {
                ViewState["ValidateOK"] = value;
            }
        }

        /// <summary>
        /// 记录查询结果集(收费记录)
        /// </summary>
        private DataTable dtSourceShouFeiJL
        {
            get
            {
                return ViewState["dtSourceShouFeiJL"] as DataTable;
            }
            set
            {
                ViewState["dtSourceShouFeiJL"] = value;
            }
        }

        /// <summary>
        /// 记录查询结果集(本次收费记录)
        /// </summary>
        private DataTable dtSourceShouFeiJLBC
        {
            get
            {
                return ViewState["dtSourceShouFeiJLBC"] as DataTable;
            }
            set
            {
                ViewState["dtSourceShouFeiJLBC"] = value;
            }
        }

        /// <summary>
        /// 记录查询结果集(欠费记录)
        /// </summary>
        private DataTable dtSourceQianFeiJL
        {
            get
            {
                return ViewState["dtSourceQianFeiJL"] as DataTable;
            }
            set
            {
                ViewState["dtSourceQianFeiJL"] = value;
            }
        }

        /// <summary>
        /// 记录查询结果集
        /// </summary>
        private DataTable dtSourceShouFeiJLHZ
        {
            get
            {
                return ViewState["dtSourceShouFeiJLHZ"] as DataTable;
            }
            set
            {
                ViewState["dtSourceShouFeiJLHZ"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _spHelper = new SpHelper();

        /// <summary>
        /// 用户信息BLL
        /// </summary>
        YS_YG_YONGHUXXBLL _YS_YG_YONGHUXXBLL = new YS_YG_YONGHUXXBLL();

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
                LoadDataShouFeiJL(true);
                LoadDataShouFeiJLHZ(true);
            }
            else
            {
                LoadDataShouFeiJL(false);
                LoadDataShouFeiJLHZ(false);
            }
            LoadDataQianFeiJL(false, false);     
        }

        
        /// <summary>
        /// 收费总账中收费日期变化时,重新查询数据
        /// </summary>
        protected void tab2txtSHOUFEIRQ_ValueChanged(object sender, EventArgs e)
        {
            LoadDataShouFeiJL(true);
        }

        /// <summary>
        /// 删除选中本次收费记录
        /// </summary>
        protected void lnbDel_Command(object sender, CommandEventArgs e)
        {
            string keyvalue = Convert.ToString(e.CommandArgument);
            int rowindex = -1;
            for (int i = 0; i < this.dtSourceShouFeiJLBC.Rows.Count; i++)
            {
                if (Convert.ToString(this.dtSourceShouFeiJLBC.Rows[i]["I_FEIYONGBH"]) == keyvalue)
                {
                    rowindex = i;
                }
            }
            this.dtSourceShouFeiJLBC.Rows.RemoveAt(rowindex);
            RecreateBenCiSFListSumJE();
            ReLoadBenCiSFJL();
            this.btnQUERENSF.Enabled = (this.dtSourceShouFeiJLBC.Rows.Count > 0);
            SetBCSFQK();
        }

        /// <summary>
        /// 列表二定位
        /// </summary>
        protected void tab2btnGOTO_Click(object sender, EventArgs e)
        {
            if (this.tab2txtYONGHUH.Text.Trim() != "")
            {
                int id = PageTools.FocusOpreateRecord(this.dtSourceShouFeiJL, this.gvShouFeiJL, "S_YONGHUH", this.tab2txtYONGHUH.Text, true);
                if (id == -1)
                {
                    PageTools.AlertMsg(this, "当前数据中没有你要找的数据,请检查你输入的条件是否正确。");
                }
            }
        }

        /// <summary>
        /// 欠费记录选中项变更事件
        /// </summary>
        protected void gvQianFeiQK_FocusedRowChanged(object sender, EventArgs e)
        {
            if (this.gvQianFeiQK.FocusedRowIndex >= 0)
            {
                object[] values = (object[])this.gvQianFeiQK.GetRowValues(this.gvQianFeiQK.FocusedRowIndex, "S_YONGHUH", "I_YM", "N_YINGSHOUJE", "N_SHISHOUJE", "N_QIANFEIJE");
                this.tab1txtYONGHUH.Text = values[0].ToString();
                this.tab1txtYM.Text = values[1].ToString();
                this.tab1txtYINGSHOUJE.Text = Convert.ToDecimal(values[2]).ToString("0.00");
                this.tab1txtSHISHOUJINE.Text = Convert.ToDecimal(values[3]).ToString("0.00");
                this.tab1txtSHOUFEIJINE.Text = Convert.ToDecimal(values[4]).ToString("0.00");
                this.tab1txtSHOUFEIJINE.Focus();
            }
        }

        /// <summary>
        /// 公共异步提示
        /// </summary>
        protected void ASPxCallbackCommon_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            CallbackResult cr = new CallbackResult(e.Parameter);
            DataRowCollection drc;
            if (e.Parameter == "yonghuh")//响应用户号回车事件
            {
                //查询用户信息
                drc = this._YS_YG_YONGHUXXBLL.SelectQS_YG_YONGHUXXesDynamic("I_JLZT=0 AND S_YONGHUH='" + this.tab1txtYONGHUH.Text + "'", null).Rows;
                if (drc.Count == 0)
                {
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    cr.Msg = "该用户可能已销户或并户或改户,无法对应到用户名。";
                    e.Result = cr.ToString();
                    return;
                }
                else
                {
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = false;
                    cr.AddValue(drc[0]["S_YONGHUM"].ToString());
                    e.Result = cr.ToString();
                    return;
                }
            }
            else if (e.Parameter == "ym")//响应水量年月回车事件
            {
                //查询当前年月的欠费信息
                drc = _spHelper.P_QSSF_GETQIANFEIJL(this.tab1txtYONGHUH.Text, int.Parse(this.tab1txtYM.Text) / 100, int.Parse(this.tab1txtYM.Text) % 100).Tables[0].Rows;
                if (drc.Count == 0)
                {
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    cr.Msg = "您输入的年月,用户没有欠费信息,请您检查。";
                    e.Result = cr.ToString();
                    return;
                }
                else
                {
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = false;
                    cr.AddValue(Convert.ToDecimal(drc[0]["N_YINGSHOUJE"]).ToString("0.00"),Convert.ToDecimal(drc[0]["N_SHISHOUJE"]).ToString("0.00"));
                    e.Result = cr.ToString();
                    return;
                }
            }            
            else if (e.Parameter == "plsf")//响应收费金额回车事件
            {
                bool hasSelected=false;
                //判断是否在欠费记录中做了勾选,有勾选则执行多选添加,无则进行单项添加
                for (int i = 0; i < this.gvQianFeiQK.VisibleRowCount; i++)
                {
                    ASPxCheckBox cb = (ASPxCheckBox)gvQianFeiQK.FindRowCellTemplateControl(i, (GridViewDataColumn)gvQianFeiQK.Columns[0], "cid");
                    if (cb.Checked)
                    {                        
                        hasSelected=true;
                        break;
                    }
                }
                if (hasSelected)
                {
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = false;
                    e.Result = cr.ToString();
                    return;
                }
                else
                {
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    cr.Msg = "请在右侧勾选上记录后再操作批量添加";
                    e.Result = cr.ToString();
                    return;
                }
            }
            else if (e.Parameter == "sf")//响应收费金额回车事件
            {
                //判断用户号与用户名是否匹配
                drc = this._YS_YG_YONGHUXXBLL.SelectQS_YG_YONGHUXXesDynamic("I_JLZT=0 AND S_YONGHUH='" + this.tab1txtYONGHUH.Text + "' AND S_YONGHUM='" + this.tab1txtYONGHUM.Text + "'", null).Rows;
                if (drc.Count == 0)
                {
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    cr.Msg = "用户号与用户名不匹配,请您检查。";
                    e.Result = cr.ToString();
                    return;
                }
                //进行单项添加
                //判断是否有加价
                drc = _spHelper.P_QSSF_GETQIANFEIJL(this.tab1txtYONGHUH.Text, int.Parse(this.tab1txtYM.Text) / 100, int.Parse(this.tab1txtYM.Text) % 100).Tables[0].Rows;
                if (drc.Count < 1)
                {
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    cr.Msg = "您输入的年月,用户没有欠费信息,请您检查。";
                    e.Result = cr.ToString();
                    return;
                }
                else
                {
                    //判断是否已添加本次收费
                    if (this.dtSourceShouFeiJLBC != null)
                    {
                        for (int i = 0; i < this.dtSourceShouFeiJLBC.Rows.Count; i++)
                        {
                            if (this.dtSourceShouFeiJLBC.Rows[i]["S_YONGHUH"].ToString() == this.tab1txtYONGHUH.Text && this.dtSourceShouFeiJLBC.Rows[i]["I_YM"].ToString() == this.tab1txtYM.Text)
                            {
                                cr.IsSuccess = false;
                                cr.IsAlertMsg = true;
                                cr.Msg = "您已添加了该用户本年月数据。";
                                e.Result = cr.ToString();
                                return;
                            }
                        }
                    }
                    //判断收费金额与欠费金额是否一致
                    if (decimal.Parse(this.tab1txtSHOUFEIJINE.Text) < Convert.ToDecimal(drc[0]["N_YINGSHOUJE"]) - Convert.ToDecimal(drc[0]["N_SHISHOUJE"]))
                    {
                        cr.IsSuccess = true;
                        cr.IsAlertMsg = true;
                        cr.Msg = "收费金额与欠费金额不一致,是否确认?";
                        cr.SpecialIndetity = "confirm";
                        e.Result = cr.ToString();
                        return;
                    }
                    else if (decimal.Parse(this.tab1txtSHOUFEIJINE.Text) > Convert.ToDecimal(drc[0]["N_YINGSHOUJE"]) - Convert.ToDecimal(drc[0]["N_SHISHOUJE"]))
                    {
                        cr.IsSuccess = true;
                        cr.IsAlertMsg = true;
                        cr.Msg = "该笔费用收取指定金额会造成多收,是否确认?";
                        cr.SpecialIndetity = "confirm";
                        e.Result = cr.ToString();
                        return;
                    }
                    else
                    {
                        cr.IsSuccess = true;
                        cr.IsAlertMsg = false;
                        e.Result = cr.ToString();
                        return;
                    }
                }
            }
            else if (e.Parameter == "qrsf")//响应确认收费按钮事件
            {
                //获取下一条收费编号
                int shoufeiBH = int.Parse(BusinessTool.GETMAXVALUE("YS_SF_SHOUFEI", "I_SHOUFEIBH", null)) + 1;
                //循环更新列表中的本次收费记录到数据库
                foreach (DataRow item in this.dtSourceShouFeiJLBC.Rows)
                {
                    if (item["KEYVALUE"].ToString() != "HEJI")
                    {
                        _spHelper.P_QSSF_DANBISHOUFEI(Convert.ToInt32(item["I_FEIYONGBH"]), Convert.ToDecimal(item["N_SHOUFEIJE"]), LoginInfo.CurrentUser.Account,Convert.ToInt32(this.tab1cmbSHOUFEILX.Value), int.Parse(this.tab1txtSHOUFEIRQ.Text));
                    }
                }
                cr.IsSuccess = true;
                cr.IsAlertMsg = true;
                cr.Msg = "收费成功";
                e.Result = cr.ToString();
                return;
            }
            else if (e.Parameter == "qxsf")
            {
                if (this.gvShouFeiJL.FocusedRowIndex == -1)
                {
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    cr.Msg = "请选择要冲账的记录！";
                    e.Result = cr.ToString();
                    return;
                }
                //获取当前选中的收费记录
                object shoufeibhTemp = this.gvShouFeiJL.GetRowValues(this.gvShouFeiJL.FocusedRowIndex, "I_SHOUFEIBH");
                if (shoufeibhTemp == null)
                {
                    return;
                }
                object feiyongbhTemp = this.gvShouFeiJL.GetRowValues(this.gvShouFeiJL.FocusedRowIndex, "I_FEIYONGBH");
                object ZHANGDANBH = this.gvShouFeiJL.GetRowValues(this.gvShouFeiJL.FocusedRowIndex, "I_SHOUFEIBH");

                object JINE = this.gvShouFeiJL.GetRowValues(this.gvShouFeiJL.FocusedRowIndex, "N_JINE");
                this._spHelper.P_QSSF_DANBISHOUFEIQX(Convert.ToInt32(shoufeibhTemp), Convert.ToInt32(feiyongbhTemp), LoginInfo.CurrentUser.Account, Convert.ToString(ZHANGDANBH), Convert.ToInt32(JINE));
                //成功
                cr.IsSuccess = true;
                cr.IsAlertMsg = true;
                cr.Msg = "取消收费成功！";
                e.Result = cr.ToString();
                return;
            }
        }

        /// <summary>
        /// 执行后台操作
        /// </summary>
        protected void btnActPerform_Click(object sender, EventArgs e)
        {
            if (this.hdCollection.Get("type").ToString() == "yonghuh")
            {
                LoadDataQianFeiJL(true, false);
                this.tab1txtYM.Focus();
            }
            else if (this.hdCollection.Get("type").ToString() == "qrsf")
            {
                //更新收错冲账中数据
                LoadDataShouFeiJL(true);
                LoadDataShouFeiJLHZ(true);
                this.ClearShouFeiTab();
                this.tab1txtYONGHUH.Focus();
            }
            else if (this.hdCollection.Get("type").ToString() == "sf" || this.hdCollection.Get("type").ToString() == "plsf")
            {                
                if (this.hdCollection.Get("type").ToString() == "sf")
                {
                    //重新获取应收与实收金额
                    DataRowCollection drc = _spHelper.P_QSSF_GETQIANFEIJL(this.tab1txtYONGHUH.Text, int.Parse(this.tab1txtYM.Text) / 100, int.Parse(this.tab1txtYM.Text) % 100).Tables[0].Rows;
                    this.tab1txtYINGSHOUJE.Text = Convert.ToDecimal(drc[0]["N_YINGSHOUJE"]).ToString("0.00");
                    this.tab1txtSHISHOUJINE.Text = Convert.ToDecimal(drc[0]["N_SHISHOUJE"]).ToString("0.00");
                    addBenCiShouFeiJL(drc[0]["I_FEIYONGBH"].ToString(), this.tab1txtYM.Text, this.tab1txtSHOUFEIJINE.Text, this.tab1txtYONGHUH.Text + this.tab1txtYM.Text);
                }
                else if (this.hdCollection.Get("type").ToString() == "plsf")
                {
                    for (int i = 0; i < this.gvQianFeiQK.VisibleRowCount; i++)
                    {
                        ASPxCheckBox cb = (ASPxCheckBox)gvQianFeiQK.FindRowCellTemplateControl(i, (GridViewDataColumn)gvQianFeiQK.Columns[0], "cid");
                        if (cb.Checked)
                        {
                            object[] vals = (object[])this.gvQianFeiQK.GetRowValues(i, "I_FEIYONGBH", "I_YM", "N_QIANFEIJE", "S_YONGHUH");
                            HiddenField hkey = (HiddenField)gvQianFeiQK.FindRowCellTemplateControl(i, (GridViewDataColumn)gvQianFeiQK.Columns[0], "hKey");
                            addBenCiShouFeiJL(vals[0].ToString(), vals[1].ToString(), vals[2].ToString(), vals[0].ToString());
                        }
                    }
                }                
                //启禁用确认收费功能
                this.btnQUERENSF.Enabled = (this.dtSourceShouFeiJLBC.Rows.Count > 0);
                //设置下方条数及金额合计信息
                SetBCSFQK();
                //重新制作本次收费列表中合计行
                RecreateBenCiSFListSumJE();
                //绑定
                ReLoadBenCiSFJL();
            }
            else if (this.hdCollection.Get("type").ToString() == "qxsf")
            {
                this.LoadDataShouFeiJL(true);
                this.LoadDataShouFeiJLHZ(true);
            }
        }

        private void addBenCiShouFeiJL(string feiyongbh,string ym,string shoufeije,string keyvalue)
        {
            //判断是否已有数据,无数据则创建DATATABLE结构
            if (this.dtSourceShouFeiJLBC == null)
            {
                this.dtSourceShouFeiJLBC = new DataTable();
                this.dtSourceShouFeiJLBC.Columns.Add("S_YONGHUH");
                this.dtSourceShouFeiJLBC.Columns.Add("S_YONGHUM");
                this.dtSourceShouFeiJLBC.Columns.Add("I_YM");
                this.dtSourceShouFeiJLBC.Columns.Add("N_SHOUFEIJE");
                this.dtSourceShouFeiJLBC.Columns.Add("I_FEIYONGBH");
                this.dtSourceShouFeiJLBC.Columns.Add("KEYVALUE");
                //this.dtSourceShouFeiJLBC.Columns.Add("S_ZHANGDANBH");
            }
            //判断当前添加的是否已经添加,添加了则跳过
            foreach (DataRow rowT in this.dtSourceShouFeiJLBC.Rows)
            {
                if (rowT["I_FEIYONGBH"].ToString()==feiyongbh)
                {
                    return;
                }
            }
            //添加记录集
            DataRow row = this.dtSourceShouFeiJLBC.NewRow();
            row["S_YONGHUH"] = this.tab1txtYONGHUH.Text;
            row["S_YONGHUM"] = this.tab1txtYONGHUM.Text;
            row["I_YM"] = ym;
            row["N_SHOUFEIJE"] = shoufeije;
            row["KEYVALUE"] = keyvalue;
            row["I_FEIYONGBH"] = feiyongbh;
            //row["S_ZHANGDANBH"] = szhangdanbh;
            //新增的收费记录添加到本次收费记录集中
            this.dtSourceShouFeiJLBC.Rows.Add(row);
        }

        /// <summary>
        /// 重新绑定本次收费记录到页面上
        /// </summary>
        private void ReLoadBenCiSFJL()
        {
            this.gvBenCiSF.DataSource = this.dtSourceShouFeiJLBC;
            this.gvBenCiSF.DataBind();
            for (int i = 0; i < this.gvBenCiSF.VisibleRowCount; i++)
            {
                if (Convert.ToString(this.gvBenCiSF.GetRowValues(i, "KEYVALUE")) == "HEJI")
                {
                    LinkButton lb = (LinkButton)gvBenCiSF.FindRowCellTemplateControl(i, (GridViewDataColumn)gvBenCiSF.Columns[5], "lnbDel");
                    lb.Visible = false;
                }
            }
        }

        /// <summary>
        /// 重新生成本次收费列表中的合计金额
        /// </summary>
        private void RecreateBenCiSFListSumJE()
        {
            //移除合计行
            int hejiIndex = -1;
            for (int i = 0; i < this.dtSourceShouFeiJLBC.Rows.Count; i++)
            {
                if (this.dtSourceShouFeiJLBC.Rows[i]["KEYVALUE"].ToString() == "HEJI")
                {
                    hejiIndex = i;
                    break;
                }
            }
            if (hejiIndex != -1)
            {
                this.dtSourceShouFeiJLBC.Rows.RemoveAt(hejiIndex);
            }
            //重新制作合计行
            decimal hejiValue = 0;
            foreach (DataRow rowT in dtSourceShouFeiJLBC.Rows)
            {
                hejiValue = hejiValue + Convert.ToDecimal(rowT["N_SHOUFEIJE"]);
            }
            if (hejiValue != 0)
            {
                DataRow rowT = this.dtSourceShouFeiJLBC.NewRow();
                rowT["S_YONGHUH"] = "";
                rowT["S_YONGHUM"] = "";
                rowT["I_YM"] = "合计";
                rowT["N_SHOUFEIJE"] = hejiValue;
                rowT["KEYVALUE"] = "HEJI";
                this.dtSourceShouFeiJLBC.Rows.Add(rowT);
            }
        }

      

        #region 方法

        /// <summary>
        /// 初始化控件
        /// </summary>
        private void InitControl()
        {
            //加载当前账务年月
            this.tab1txtSHOUFEIRQ.Text = BusinessTool.GetSLYMorZWNY(2, 2).ToString();
            this.tab2txtZWYM.Text = this.tab1txtSHOUFEIRQ.Text;
            //加载收错冲账选项卡中收费记录及汇总
            this.tab2txtSHOUFEIRQ.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            //确认收费初始不可用
            this.btnQUERENSF.Enabled = false;
        }

        /// <summary>
        /// 查询收错冲账中收费记录
        /// </summary>
        /// <param name="reGet">是否重新读取数据库</param>
        private void LoadDataShouFeiJL(bool reGet)
        {
            if (reGet)
            {
                this.dtSourceShouFeiJL = _spHelper.P_QSSF_GETZPXJFWSFJL(this.tab2txtSHOUFEIRQ.Date, this.tab2txtZWYM.Text).Tables[0];
            }
            this.gvShouFeiJL.DataSource = this.dtSourceShouFeiJL;
            this.gvShouFeiJL.DataBind();
        }

        /// <summary>
        /// 查询收错冲账中汇总数据
        /// </summary>
        /// <param name="reGet">是否重新读取数据库</param>
        private void LoadDataShouFeiJLHZ(bool reGet)
        {
            if (true)
            {
                this.dtSourceShouFeiJLHZ = SearchSpHelper.P_QSSF_GETZPXJFWSFJLHZ(this.tab2txtSHOUFEIRQ.Date, this.tab2txtZWYM.Text).Tables[0];
            }
            this.gvShouFeiJLHZ.DataSource = this.dtSourceShouFeiJLHZ;
            this.gvShouFeiJLHZ.DataBind();
        }

        /// <summary>
        /// 查询GRIDVIEW数据
        /// </summary>
        /// <param name="reGet">是否重新读取数据库</param>
        ///  <param name="clear">是否清空数据源</param>
        private void LoadDataQianFeiJL(bool reGet, bool clear)
        {
            //记录当前勾选的项
            Dictionary<string, string> listChecked = new Dictionary<string, string>();
            for (int i = 0; i < this.gvQianFeiQK.VisibleRowCount; i++)
            {
                ASPxCheckBox cb = (ASPxCheckBox)gvQianFeiQK.FindRowCellTemplateControl(i, (GridViewDataColumn)gvQianFeiQK.Columns[0], "cid");
                if (cb.Checked)
                {
                    string keyvalue = Convert.ToString(gvQianFeiQK.GetRowValues(i, "I_FEIYONGBH"));
                    //HiddenField hkey = (HiddenField)gvQianFeiQK.FindRowCellTemplateControl(i, (GridViewDataColumn)gvQianFeiQK.Columns[0], "hKey");
                    listChecked.Add(keyvalue, keyvalue);
                }
            }
            if (clear)
            {
                this.dtSourceQianFeiJL = null;
            }
            else if (reGet)
            {
                this.dtSourceQianFeiJL = _spHelper.P_QSSF_GETQIANFEIJL(this.tab1txtYONGHUH.Text, null, null).Tables[0];
            }
            this.gvQianFeiQK.DataSource = this.dtSourceQianFeiJL;
            this.gvQianFeiQK.DataBind();
            //勾选之前勾选过的
            for (int i = 0; i < gvQianFeiQK.VisibleRowCount; i++)
            {
                string keyvalue = Convert.ToString(gvQianFeiQK.GetRowValues(i,"I_FEIYONGBH"));
                //HiddenField hkey = (HiddenField)gvQianFeiQK.FindRowCellTemplateControl(i, (GridViewDataColumn)gvQianFeiQK.Columns[0], "hKey");
                if (listChecked.ContainsKey(keyvalue))
                {
                    ((ASPxCheckBox)gvQianFeiQK.FindRowCellTemplateControl(i, (GridViewDataColumn)gvQianFeiQK.Columns[0], "cid")).Checked = true;
                }
            }
        }

        /// <summary>
        /// 清空收费选项卡内容
        /// </summary>
        private void ClearShouFeiTab()
        {
            this.tab1txtSHISHOUJINE.Text = "";
            this.tab1txtSHOUFEIJINE.Text = "";
            this.tab1txtYINGSHOUJE.Text = "";
            this.tab1txtYM.Text = "";
            this.tab1txtYONGHUH.Text = "";
            this.tab1txtYONGHUM.Text = "";
            this.dtSourceShouFeiJLBC.Rows.Clear();
            this.gvBenCiSF.DataSource = this.dtSourceShouFeiJLBC;
            this.gvBenCiSF.DataBind();
            this.dtSourceQianFeiJL.Rows.Clear();
            this.gvQianFeiQK.DataSource = this.dtSourceQianFeiJL;
            this.gvQianFeiQK.DataBind();
            this.btnQUERENSF.Enabled = false;
        }

        /// <summary>
        /// 设置显示本次收费情况
        /// </summary>
        private void SetBCSFQK()
        {
            //显示收费条数与总金额
            decimal moneySum = 0;
            for (int i = 0; i < this.dtSourceShouFeiJLBC.Rows.Count; i++)
            {
                moneySum += Convert.ToDecimal(this.dtSourceShouFeiJLBC.Rows[i]["N_SHOUFEIJE"]);
            }
            if (this.dtSourceShouFeiJLBC == null || this.dtSourceShouFeiJLBC.Rows.Count == 0)
            {
                this.lblShouFeiTip.Text = "";
            }
            else
            {
                this.lblShouFeiTip.Text = "本次收费" + this.dtSourceShouFeiJLBC.Rows.Count.ToString() + "笔,金额共计:" + moneySum.ToString("0.00");
            }
        }

        #endregion
    }
}